let arryAll = ["main", "printf", "scanf_s"]

// 需要一个字符串的代码，这里面会对他进行一些操作
function main(string){
  string = angleBrackets(string)
  string = funcStyleSystem(string)
  string = funcStyleMy(string)
  string = keyWord(string)
  string = lineFeed(string)
  string = varStyle(string)
  string = numStyle(string)
  string = key(string)
  return string
}

function angleBrackets(string){
  string = string.replace(/</g, "&lt;").replace(/>/g, "&gt;")
  let strArry = string.match(/&lt;.*?&gt;/g)
  if(strArry){
    for(let str of strArry){
      string = string.replace(str, "<span class='varStyle'>"+str+"</span>")
    }
  }
  return string
}

function keyWord(string){
  let arryRe = [/auto /g,/short /g,/int /g,/long /g,/float /g,/double /g,/char /g,/struct /g,/union /g,/enum /g,/typedef /g,/const /g,/unsigned /g,/signed /g,/extern /g,/register /g,/static /g,/volatile /g,/void /g,/if /g,/else /g,/switch /g,/case /g,/for /g,/do /g,/while /g,/goto /g,/continue/g,/break/g,/default /g,/sizeof /g,/return /g]
  let arryKeyWord = ['auto ', 'short ', 'int ', 'long ', 'float ', 'double ', 'char ', 'struct ', 'union ', 'enum ', 'typedef ', 'const ', 'unsigned ', 'signed ', 'extern ', 'register ', 'static ', 'volatile ', 'void ', 'if ', 'else ', 'switch ', 'case ', 'for ', 'do ', 'while ', 'goto ', 'continue', 'break', 'default ', 'sizeof ', 'return ']
  let keyPointer = ["int\\*", "long int\\*", "long long int\\*", "float\\*", "double\\*", "void\\*", "enum\\*", "boolean\\*", "char\\*", "string\\*"]
  for(let i in arryRe){
    string = string.replace(arryRe[i], "<span class='keyWordStyle'>" + arryKeyWord[i] + "</span>")
  }
  for(let p of keyPointer){
    let pRe = new RegExp(p, 'g')
    let str = p.replace("\\*","")
    string = string.replace(pRe, "<span class='keyWordStyle'>" + str + "*" + "</span>")
  }
  return string
}

function lineFeed(string){
  string = string.replace(/\n/g, "<br/>")
  let str = string.match(/".*<br\/>.*"/g)
  for(let i in str){
    str[i] = str[i].replace(/<br\/>/, '\\n')
    string = string.replace(/".*<br\/>.*"/, str[i])
  }
  return string
}

function funcStyleMy(string){
  let arryOne = [/void .*?\(/g,/int .*?\(/g,/long int .*?\(/g,/long long int .*?\(/g,/float .*?\(/g,/double .*?\(/g,/enum .*?\(/g]
  let arryTwo = ['void ', 'int ', 'long int ', 'long long int ', 'float ', 'double ', 'enum ']
  for(let index in arryOne){
    let strArry = string.match(arryOne[index])
    if(strArry){
      for(let strItem of strArry){
        let str = strItem.replace(arryTwo[index], "").replace("(","")
        if(arryAll.indexOf(str)==-1){
          let strRe = new RegExp(str, 'g')
          string = string.replace(strRe, "<span class='funcStyleMy'>"+str+"</span>")
        }
      }
    }
  }
  return string
}

function funcStyleSystem(string){
  let arry = arryAll
  for(let key of arry){
    let strRe = new RegExp(key, 'g')
    string = string.replace(strRe, "<span class='funcStyleSystem'>"+key+"</span>")
  }
  return string
}

function varStyle(string){
  let strArry = string.match(/".*?"/g)
  if(strArry){
    for(let str of strArry){
      string = string.replace(str, "<span class='varStyle'>"+str+"</span>")
    }
  }
  return string
}

function numStyle(string){
  for(let i=0;i<10;i++){
    let numRe = new RegExp(String(i), 'g')
    string = string.replace(numRe, "<span class='numStyle'>"+i+"</span>")
  }
  return string
}

function key(string){
  string = string.replace("#include", "<span class='keyEspecially'>#include</span>")
  string = string.replace("#define", "<span class='keyEspecially'#define</span>")
  return string
}

export default main
